package com.education.music.activity;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;

import com.education.music.R;
import com.education.music.util.CommSharedUtil;

public class UserInfoActivity extends AppCompatActivity {

    private EditText et_username;
    private EditText et_sigin;
    private TextView tv_phone;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_info);
        initView();
    }

    private void initView() {
        et_username = findViewById(R.id.et_username);
        et_sigin = findViewById(R.id.et_sigin);
        tv_phone = findViewById(R.id.tv_phone);

        setFocusable(et_username);
        setFocusable(et_sigin);

        et_username.setText(CommSharedUtil.getInstance(this).getString("username")+"");
        et_sigin.setText(CommSharedUtil.getInstance(this).getString("sigin")+"");
        tv_phone.setText(CommSharedUtil.getInstance(this).getString("phone"));

        et_username.setOnClickListener(v -> {
            //todo 可编辑状态，填写用户名字
            setCanFocusable(et_username);
        });
        et_sigin.setOnClickListener(v -> {
            //todo 可编辑状态，填写用户签名
            setCanFocusable(et_sigin);
        });

        et_username.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                //todo 保存用户名字
                CommSharedUtil.getInstance(UserInfoActivity.this).putString("username",s.toString());
            }
        });

        et_sigin.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                //todo 保存用户签名
                CommSharedUtil.getInstance(UserInfoActivity.this).putString("sigin",s.toString());
            }
        });

    }

    private void setCanFocusable(EditText editText) {
        editText.setFocusableInTouchMode(true);
        editText.setFocusable(true);
        editText.requestFocus();
    }

    private void setFocusable(EditText editText) {
        editText.setFocusable(false);
        editText.setFocusableInTouchMode(false);
    }


}
